home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / pmdev / c / demos / disable.c < prev    next >
C/C++ Source or Header  |  2000-02-28  |  3KB  |  103 lines

  1. //
  2. // $VER: Disable.c 2.0 (05.09.98)
  3. //
  4. // Popup Menu example program
  5. //
  6. // ©1996-1997 Henrik Isaksson
  7. // All Rights Reserved.
  8. //
  9. // Run and click the mouse in the window!
  10. //
  11.  
  12. #include <intuition/intuition.h>
  13.  
  14. #include <proto/intuition.h>
  15. #include <proto/exec.h>
  16.  
  17. #include <clib/alib_protos.h>
  18.  
  19. #include <string.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22.  
  23. #include <libraries/pm.h>
  24. #include <proto/pm.h>
  25.  
  26. struct IntuitionBase    *IntuitionBase;
  27. struct GfxBase        *GfxBase;
  28. struct PopupMenuBase    *PopupMenuBase;
  29.  
  30. struct Window *w;    // This window is only needed to find out when and where the menu should appear.
  31.             // The font in this window's rastport will be used for the menu.
  32.  
  33. void main()
  34. {
  35.     BOOL r=TRUE;
  36.     struct IntuiMessage *im,imsg;
  37.     struct PopupMenu *p;
  38.  
  39.     PopupMenuBase=(struct PopupMenuBase *)OpenLibrary(POPUPMENU_NAME,POPUPMENU_VERSION);            // Open the library
  40.     if(PopupMenuBase) {
  41.         IntuitionBase=(struct IntuitionBase *)PopupMenuBase->pmb_IntuitionBase;    // We let popupmenu.library open the libraries we need
  42.         GfxBase=(struct GfxBase *)PopupMenuBase->pmb_GfxBase;            // They remain valid until the library is closed!
  43.  
  44.         p=PMMenu("Plain Simple Menu!"),    // Create a very simple menu...
  45.  
  46.             PMCheckItem("Enable quit?",10),                                PMEnd,
  47.  
  48.             PMTitleBar,                                        PMEnd,
  49.  
  50.             PMItem("Quit"),        PM_Sub,
  51.                 PM_MakeMenu(
  52.                     PMItem("Quit"),        PM_Disabled,    TRUE,    PM_UserData,    5,    PM_ID,    15,    PMEnd,
  53.                 PMEnd, /* MakeMenu */
  54.  
  55.             PMEnd, /* PMItem */
  56.  
  57.         End; /* PMMenu */
  58.  
  59.         if(p) {
  60.             w=OpenWindowTags(NULL,    WA_IDCMP,    IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS,    // Open a little window
  61.                     WA_RMBTrap,    TRUE,
  62.                     WA_DragBar,    TRUE,
  63.                     WA_Width,    150,
  64.                     WA_Height,    100,
  65.                     WA_Left,    0,
  66.                     WA_Top,        0,
  67.                     WA_Title,    "Disable & Enable",
  68.                     WA_CloseGadget,    TRUE,
  69.                     TAG_DONE);
  70.             if(w) {
  71.                 while(r) {
  72.                     WaitPort(w->UserPort);                        // Wait for a message
  73.                     while((im=(struct IntuiMessage *)GetMsg(w->UserPort))) {    // Get the message
  74.                         CopyMem(im,&imsg,sizeof(struct IntuiMessage));        // Copy the contents of it
  75.                         ReplyMsg((struct Message *)im);                // Reply the message
  76.  
  77.                         switch(imsg.Class) {
  78.                             case IDCMP_CLOSEWINDOW: r=FALSE; break;
  79.                             case IDCMP_MOUSEBUTTONS:            // The user has hit a mousebutton - time to open the menu!
  80.                                 r=(BOOL)((ULONG)(PM_OpenPopupMenu(w,
  81.                                         PM_Menu,        p,
  82.                                         PM_Code,        imsg.Code,
  83.                                         TAG_DONE))-5);
  84.                                         
  85.                                 if(PM_ItemChecked(p,10)) {    // See if "Enable quit?" is checked
  86.                                     // Find the item and enable it
  87.                                     PM_SetItemAttrs(PM_FindItem(p, 15), PM_Disabled, FALSE, TAG_DONE);
  88.                                 } else {
  89.                                     // Find the item and disable it
  90.                                     PM_SetItemAttrs(PM_FindItem(p, 15), PM_Disabled, TRUE, TAG_DONE);
  91.                                 }
  92.                             break;
  93.                         }
  94.                     }
  95.                 }
  96.                 CloseWindow(w);
  97.             } else printf("Window error!\n");
  98.             PM_FreePopupMenu(p);
  99.         } else printf("Menu error!\n");
  100.         CloseLibrary((struct Library *)PopupMenuBase);
  101.     }
  102. }
  103.